package com.roc.steelend.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.roc.steelend.controller.vo.returnformat.ReturnMsg;
import com.roc.steelend.controller.vo.returnformat.ReturnMsgForTable;
import com.roc.steelend.mapper.SmallTypeMapper;
import com.roc.steelend.pojo.SmallType;
import com.roc.steelend.service.SmallTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class SmallTypeServiceImpl implements SmallTypeService {

    @Autowired
    private SmallTypeMapper smallTypeMapper;
    @Override
    public List<HashMap<String, Object>> findSmallTypeByBigType(Integer bigTypeId) {
        return smallTypeMapper.findSmallTypeByBigType(bigTypeId);
    }

    @Override
    public List<HashMap<String, Object>> findSmallTypeShowReverse() {
        return smallTypeMapper.findSmallTypeShowReverse();
    }

    @Override
    public List<SmallType> findSmallTypeShowCondition(Integer bigTypeId) {
        QueryWrapper<SmallType> wrapper = new QueryWrapper<>();
        if (bigTypeId!=null){
            wrapper.eq("big_type_id",bigTypeId);
        }


        return smallTypeMapper.selectList(wrapper);
    }

    @Override
    public ReturnMsgForTable findSmallTypeShowDetail(Integer now, Integer size, Integer bigTypeId) {
        ReturnMsgForTable returnMsgForTable = new ReturnMsgForTable();
        returnMsgForTable.setCurrenPage(now);
        now=(now-1)*size;

        returnMsgForTable.setObjectList(smallTypeMapper.findSmallTypeShowDetail(now,size,bigTypeId));
        returnMsgForTable.setTotal(smallTypeMapper.findSmallTypeShowDetailCount(bigTypeId));
        return returnMsgForTable;
    }
}
